#include <stdio.h>
#include <string.h>

char name[400][100];
int n,m; // n for nod, m for edge
int map[400][400];
int outmap[400][400];
int start,end;
int record[400];
int an[400];
int finish;
int sign[400];

int getname(char *s)
{
	int i;
	for (i=1;i<=n;i++)
		if (strcmp(name[i],s)==0)
			return i;
	strcpy(name[++n],s);
	return n;
}

int exist(int b)
{
	int i;
	for (i=2;i<=record[0];i++)
		if (record[i]==b)
			if (record[i-1]==record[record[0]])
				return 1;
	return 0;
}

int checkfinish()
{
	int i,tot=0;

	memset(sign,0,sizeof(sign));
	for (i=1;i<=record[0];i++)
		if (sign[i]==0)
		{
			sign[i]=1;
			tot++;
		}
	if (tot==n) return 1;
	else return 0;

}

void search(int a)
{
	int i;
	if (finish) return;
	record[++record[0]]=a;
	if (a==end)
		if (checkfinish())
		{
			finish=1;
			for (i=0;i<=record[0];i++) an[i]=record[i];
			return;
		}
	
	for (i=1;i<=map[a][0];i++)
	{
		if (!exist(map[a][i]))
		{
			search(map[a][i]);
		}
	}
	record[0]--;
}

main()
{
	int icase=0, ncase;
	char s1[100], s2[100];
	int i, a, b;
	
	scanf("%d", &ncase);
	while( ncase-->0 )
	{
		n=0;
		memset(map,0,sizeof(map));
		memset(outmap,0,sizeof(outmap));
		memset(name,0,sizeof(name));
		memset(record,0,sizeof(record));

		scanf("%d", &m);
		for (i=1;i<m;i++)
		{
			scanf("%s%s", s1, s2);
			a=getname(s1);
			b=getname(s2);
			map[a][++map[a][0]]=b; //有向图					  
			outmap[b][++outmap[b][0]]=a;
		}


		for (i=1;i<=n;i++)
			if (map[i][0]>outmap[i][0]) 
			{
				start=i;
				break;
			}
		for (i=1;i<=n;i++)
			if (map[i][0]<outmap[i][0])
			{
				end=i;
				break;
			}
		finish=0;
		search(start);
		printf("Scenario #%d:\n", ++icase);
		for (i=1;i<=an[0];i++)
			printf("%s\n", name[an[i]]);
		printf("\n");
	}


	return 0;
}